import { lazy, StrictMode } from "react";
import { createRoot } from "react-dom/client";
import "./index.css";
import { BrowserRouter } from "react-router";
import svg1 from "./assets/icons/svg1.ts";
import svg2 from "./assets/icons/svg2.ts";
import svg3 from "./assets/icons/svg3.ts";
import svg4 from "./assets/icons/svg4.ts";
import { ConfigProvider } from "antd";
import zhCN from "antd/locale/zh_CN";
import {
  fetchGetUserInfo,
  setPhoneNumber,
  setUserId,
} from "./api/server/recommend_question.ts";

export async function initRoot() {
  const svgIconDiv = document.createElement("div");

  svgIconDiv.innerHTML = svg1 + svg2 + svg3 + svg4;
  document.body.prepend(svgIconDiv);
  const LazyApp = lazy(() => import("./App.tsx"));

  const res = await fetchGetUserInfo();

  const info = res?.data?.result;
  setUserId(info?.user_id);
  setPhoneNumber(info?.phone_number);

  console.log(res);

  createRoot(document.getElementById("root")!).render(
    <StrictMode>
      <ConfigProvider locale={zhCN}>
        <BrowserRouter>
          <LazyApp />
        </BrowserRouter>
      </ConfigProvider>
    </StrictMode>
  );
}
